package com.ruoyi.crm.controller;

import java.util.List;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.crm.domain.CrmGh;
import com.ruoyi.crm.service.ICrmGhService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公海/私海客户信息Controller
 * 
 * @author ruoyi
 * @date 2023-03-30
 */
@RestController
@RequestMapping("/crm")
public class CrmGhController extends BaseController
{
    @Autowired
    private ICrmGhService crmGhService;

    /**
     * 查询公海客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('crm:gh:list')")
    @GetMapping("/listGh")
    public TableDataInfo listGh(CrmGh crmGh)
    {
        startPage();
        crmGh.setCondition(0);
        List<CrmGh> list = crmGhService.selectCrmGhList(crmGh);
        return getDataTable(list);
    }

    /**
     * 查询私海客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('crm:gh:list')")
    @GetMapping("/listSh")
    public TableDataInfo listSh(CrmGh crmGh)
    {
        startPage();
        crmGh.setCondition(1);
        List<CrmGh> list = crmGhService.selectCrmGhList(crmGh);
        return getDataTable(list);
    }

    /**
     * 导出公海/私海客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('crm:gh:export')")
    @Log(title = "公海/私海客户信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmGh crmGh)
    {
        List<CrmGh> list = crmGhService.selectCrmGhList(crmGh);
        ExcelUtil<CrmGh> util = new ExcelUtil<CrmGh>(CrmGh.class);
        String sheetName= "";
        if(crmGh.getCondition().equals(0)){
            sheetName="gh";
        }else{
            sheetName="sh";
        }
        return util.exportExcel(list, sheetName);
    }

    /**
     * 获取公海/私海客户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:gh:query')")
    @GetMapping( "query")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmGhService.selectCrmGhById(id));
    }

    /**
     * 新增公海客户信息
     */
    @PreAuthorize("@ss.hasPermi('crm:gh:add')")
    @Log(title = "新增公海客户信息", businessType = BusinessType.INSERT)
    @PostMapping("addGH")
    public AjaxResult add(/*@RequestBody*/ CrmGh crmGh)
    {
        crmGh.setCondition(0);
        return toAjax(crmGhService.insertCrmGh(crmGh));
    }


    /**
     * 新增私海客户信息
     */
    @PreAuthorize("@ss.hasPermi('crm:gh:add')")
    @Log(title = "新增私海客户信息", businessType = BusinessType.INSERT)
    @PostMapping("addSH")
    public AjaxResult addSh(/*@RequestBody*/ CrmGh crmGh)
    {
        crmGh.setCondition(1);
        return toAjax(crmGhService.insertCrmGh(crmGh));
    }


    /**
     * 修改公海/私海客户信息
     */
    @PreAuthorize("@ss.hasPermi('crm:gh:edit')")
    @Log(title = "公海/私海客户信息编辑", businessType = BusinessType.UPDATE)
    @PutMapping("edit")
    public AjaxResult edit(@RequestBody CrmGh crmGh)
    {
        return toAjax(crmGhService.updateCrmGh(crmGh));
    }


    /**
     * 修改公海客户信息伟私海客户信息为私海客户信息
     */
    @PreAuthorize("@ss.hasPermi('crm:gh:edit')")
    @Log(title = "修改公海客户信息伟私海客户信息为私海客户信息", businessType = BusinessType.UPDATE)
    @PutMapping("alterById")
    public AjaxResult updateConditionById(/*@RequestBody*/ CrmGh crmGh)
    {
        return toAjax(crmGhService.updateConditionById(crmGh));
    }


    /**
     * 批量修改公海客户信息为私海客户信息
     */
    @PreAuthorize("@ss.hasPermi('crm:gh:edit')")
    @Log(title = "批量修改公海客户信息为私海客户信息", businessType = BusinessType.UPDATE)
    @PutMapping("alterByIds")
    public AjaxResult updateConditionByIds(/*@RequestBody*/ Long[] ids)
    {
        return toAjax(crmGhService.updateConditionByIds(ids));
    }

    /**
     * 删除公海/私海客户信息
     */
    @PreAuthorize("@ss.hasPermi('crm:gh:remove')")
    @Log(title = "公海/私海客户信息批量删除", businessType = BusinessType.DELETE)
	@DeleteMapping("del")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmGhService.deleteCrmGhByIds(ids));
    }
}
